import { axios } from '@/utils/request'

const api = {
  // 基础接口
  list: '/wms/finished-goods/inventory/list',
  byOrder: '/wms/finished-goods/inventory/by-order',
  orderDetails: '/wms/finished-goods/inventory/order-details',
  adjust: '/wms/finished-goods/inventory/adjust',
  reserve: '/wms/finished-goods/inventory/reserve',
  release: '/wms/finished-goods/inventory/release',
  logs: '/wms/finished-goods/inventory/logs',
  
  // 统计接口
  statisticsOverview: '/wms/finished-goods/inventory/statistics/overview',
  statisticsWarehouse: '/wms/finished-goods/inventory/statistics/warehouse',
  statisticsOrder: '/wms/finished-goods/inventory/statistics/order',
  statisticsWindowSeries: '/wms/finished-goods/inventory/statistics/window-series',
  
  // 导出接口
  exportXls: '/wms/finished-goods/inventory/exportXls',
  importExcel: '/wms/finished-goods/inventory/importExcel'
}

/**
 * 获取成品库存列表
 * @param params 查询参数
 * @returns {Promise}
 */
export function getFinishedGoodsInventoryList(params) {
  return axios({
    url: api.list,
    method: 'get',
    params: params
  })
}

/**
 * 按订单查询库存
 * @param params 查询参数
 * @returns {Promise}
 */
export function getInventoryByOrder(params) {
  return axios({
    url: api.byOrder,
    method: 'get',
    params: params
  })
}

/**
 * 获取订单库存详情
 * @param orderNo 订单号
 * @returns {Promise}
 */
export function getOrderInventoryDetails(orderNo) {
  return axios({
    url: `${api.orderDetails}/${orderNo}`,
    method: 'get'
  })
}

/**
 * 库存调整
 * @param data 调整数据
 * @returns {Promise}
 */
export function adjustInventory(data) {
  return axios({
    url: api.adjust,
    method: 'post',
    data: data
  })
}

/**
 * 库存预留
 * @param data 预留数据
 * @returns {Promise}
 */
export function reserveInventory(data) {
  return axios({
    url: api.reserve,
    method: 'post',
    data: data
  })
}

/**
 * 库存释放
 * @param data 释放数据
 * @returns {Promise}
 */
export function releaseInventory(data) {
  return axios({
    url: api.release,
    method: 'post',
    data: data
  })
}

/**
 * 获取库存变动记录
 * @param params 查询参数
 * @returns {Promise}
 */
export function getInventoryLogs(params) {
  return axios({
    url: api.logs,
    method: 'get',
    params: params
  })
}

/**
 * 获取库存统计概览
 * @returns {Promise}
 */
export function getInventoryStatisticsOverview() {
  return axios({
    url: api.statisticsOverview,
    method: 'get'
  })
}

/**
 * 按仓库统计库存
 * @returns {Promise}
 */
export function getInventoryStatisticsByWarehouse() {
  return axios({
    url: api.statisticsWarehouse,
    method: 'get'
  })
}

/**
 * 按订单统计库存
 * @returns {Promise}
 */
export function getInventoryStatisticsByOrder() {
  return axios({
    url: api.statisticsOrder,
    method: 'get'
  })
}

/**
 * 按门窗系列统计库存
 * @returns {Promise}
 */
export function getInventoryStatisticsByWindowSeries() {
  return axios({
    url: api.statisticsWindowSeries,
    method: 'get'
  })
}

// 成品库存不需要低库存预警功能，按订单生产模式

/**
 * 导出Excel
 * @param params 导出参数
 * @returns {Promise}
 */
export function exportInventoryXls(params) {
  return axios({
    url: api.exportXls,
    method: 'get',
    params: params,
    responseType: 'blob'
  })
}

/**
 * 导入Excel
 * @param formData 表单数据
 * @returns {Promise}
 */
export function importInventoryExcel(formData) {
  return axios({
    url: api.importExcel,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export default api
